// ---------------------------------------------------
// Gallery Gambar Responsive Efek Scrolling Slide
// Design by. Devy Indriyani
// Input Element: JavaScript-jQuery (gallery.js)
// Published On February 04, 2015
// Visit: http://sahabatblogger77.blogspot.com
//---------------------------------------------------- 
var i, expand = false;
function reset() {
  $('.gallery').css({
    'transform': 'rotate(0deg)',
    'top' : '0px'});}
$('.gallery').click(function (a) {
  if (expand) {
    a.preventDefault();
    var imgSource = $(this).children().attr('href');
    $('#lightwrap').append('<img src="' + imgSource + '" id="lb-pic">');
    $('#lightbox, #lightwrap').fadeIn('slow');
  } else {
    var boxWidth = $('.gallery').width();
    $('.gallery').each(function (e) {
      $(this).css({
        'left': boxWidth * e * 1.1 + 'px'});
      expand = true;
      $('#close').show();});}});
/* Target show to new page image data
 join to: Sahabat Blogger 77 (http://sahabatblogger77.blogspot.com) */
$('#x, #lightbox').click(function(){
  $('#lightbox').fadeOut('slow');
  $('#lightwrap').hide();
  $('#lb-pic').remove();});
$('#lightwrap').click(function(b) {
  b.stopPropagation();});
$('#close').click(function(){
  $(this).hide();
  $('.gallery').css({'left': '0px'});
  expand = false;});
$('.gallery:last-child').hover(
  function() {
    if (expand === false) {    
      $('.gallery').each(function () {
        i++;
        if (i < $('.gallery').length) {
          var min = -30,
              max = 30,
              random = ~~(Math.random() * (max - min + 1)) + min;
          $(this).css({
            'transform' : 'rotate(' + random + 'deg)',
            'top' : random + 15 + 'px'});}});}
  $('.gallery').click(
    function (a) {
      a.preventDefault();
      reset();}); },
  function () {
    i = 0;reset();});